package root.action;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Demo2
 */
@WebServlet("/Demo2")
public class Demo2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Demo2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		servlet版本必须要3.0+
		ServletContext application = request.getServletContext();
		application.setRequestCharacterEncoding("utf-8");
		application.setResponseCharacterEncoding("utf-8");
		
		
//		servlet版本在3.0-
		ServletContext application2 = request.getSession().getServletContext();
//		在application对象中 可以设置全局session作用域的过期时间
		application2.setSessionTimeout(30);

		application2.setAttribute("name", "value1");
		application2.setAttribute("name", "value2");
		application2.setAttribute("name", "value3");
		application2.getAttribute("name");
		application2.removeAttribute("name");
		

		
		
		
		
		
		
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
